<template>
  <div class="content2">
    <!-- 轮播 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(banner, index) in bannerList" :key="index">
        <img :src="banner.picUrl" alt="" class="swpierimg" />
      </van-swipe-item>
    </van-swipe>

    <!-- 组件 -->
    <div class="mainfloor" v-for="(f1, index) in categoryItemList" :key="index">
      <div class="top">
        <div class="text1">{{ f1.category.name }}</div>
        <div class="text2">{{ f1.category.frontName }}</div>
      </div>
      <div class="bootom">
        <div class="bootom-item" v-for="(f2, index) in f1.itemList" @click="jumptodetail" :key="index">
          <img class="img" :src="f2.listPicUrl" alt="" />
          <div class="center">{{ f2.name }}</div>
          <div class="price"><span class="span">￥</span>{{ f2.retailPrice }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
  name: 'Item'
})
</script>

<script lang="ts" setup>
import { onMounted, ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import homeapi from '../../api/home/home'
import { showFailToast } from 'vant'
const props = defineProps<{
  category: unknown
  id: number
}>()

//总的数据结构
const tiemData = ref<any>()

const router = useRouter()

// 获取导航的数据
const getItem = async (id: number) => {
  try {
    const res = await homeapi.itemlist(props.id * 1)
    tiemData.value = res.data
  } catch (error) {
    showFailToast('获取列表失败')
  }
}
onMounted(() => {
  getItem(props.id)
})

// 轮播图的部分
const bannerList = computed(() => {
  return ((tiemData.value || {}).currentCategory || {}).bannerList || []
})

// 楼梯的部分
const categoryItemList = computed(() => {
  return ((tiemData.value || {}).categoryItemList || []).slice(0, 10)
})

// 跳转到详情
function jumptodetail() {
  router.push({
    path: '/detail'
  })
}
</script>

<style lang="less" scoped>
.content2 {
  height: 100%;
  // 轮播
  .my-swipe {
    width: 100%;
    height: 148px;

    .van-swipe-item {
      .swpierimg {
        width: 100%;
        height: 185px;
      }
    }
  }
  // 组件

  background-color: #eee;
  .mainfloor {
    width: 100%;
    background-color: #fff;
    margin-bottom: 10px;
    margin-left: 4px;
    .top {
      width: 100%;
      height: 60px;
      .text1 {
        padding-top: 10px;
        height: 16px;
        line-height: 16px;
        font-size: 16px;
        text-align: center;
        color: black;
      }
      .text2 {
        height: 12px;
        line-height: 12px;
        font-size: 12px;
        text-align: center;
        color: #999;
        margin: 8px 0 0;
      }
    }
    .bootom {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      .bootom-item {
        width: 187px;
        height: 281px;

        .img {
          width: 172.5px;
          height: 172.5px;
          margin: 0px 6px;
          border-radius: 10px;
        }
        .center {
          width: 100%;
          height: 45px;
          font-size: 15px;
          margin-top: 8px;
          margin-left: 2px;
          text-overflow: ellipsis;
        }
        .price {
          height: 30px;
          text-align: left;
          color: red;
          font-size: 20px;
          font-weight: 600;
          .span {
            color: red;
            font-size: 12px;
          }
        }
      }
    }
  }
}
</style>
